package com.ncloud.resman.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.ncloud.resman.constant.ResConstant;
import com.ncloud.resman.entity.DeviceLocation;
import com.ncloud.resman.mapper.DeviceLocationMapper;
import com.ncloud.resman.service.DeviceLocationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by shiqiang on 2017/8/15.
 */
@Service
public class DeviceLocationServiceImpl implements DeviceLocationService{
    @Autowired
    private DeviceLocationMapper deviceLocationMapper;
    @Override
    public DeviceLocation getLocationByDeviceId(Long deviceId) {
        return deviceLocationMapper.getLocationByDeviceId(deviceId);
    }

    @Override
    public int insertLocation(DeviceLocation deviceLocation) {
        deviceLocation.setState(ResConstant.DEVICE_LOCATION_UNONLINE);
        deviceLocation.setCreateDate(new Date());
        return deviceLocationMapper.insertDeviceLocation(deviceLocation);
    }

    @Override
    public int updateLocation(DeviceLocation deviceLocation) {
        deviceLocation.setUpdateDate(new Date());
        return deviceLocationMapper.updateDeviceLocation(deviceLocation);
    }

    @Override
    public int deleteLocation(Long deviceId) {
        return deviceLocationMapper.deleteLocation(deviceId);
    }

    @Override
    public int updateLocationSnNumByDeviceId(String snNum, Long deviceId) {
        return deviceLocationMapper.updateLocationSnNumByDeviceId(snNum,deviceId);
    }

    @Override
    public int updateDeviceLocationInvalid(Long cabinetId, Long deviceId) {
        return deviceLocationMapper.updateDeviceLocationInvalid(cabinetId,deviceId);
    }

    @Override
    public int updateDeviceLocationUse(Long cabinetId, Integer useNum,Long deviceId) {
        return deviceLocationMapper.updateDeviceLocationUse(cabinetId,useNum,deviceId);
    }

    @Override
    public List<Map<String,Object>> getDeviceLocationList(String eqptType, String state) {
        return deviceLocationMapper.getDeviceLocationList(eqptType,state);
    }

    @Override
    public int queryLocationUseCount(Long cabinetId,int uNum) {
        return deviceLocationMapper.queryLocationUseCount(cabinetId,uNum);
    }

    @Override
    public int updateCabinetUseStateByDevice(Long deviceId) {
        return deviceLocationMapper.updateCabinetUseStateByDevice(deviceId);
    }
	@Override
	public String getCabinetUseState(String cabinetId, String useNum) {
		return deviceLocationMapper.getCabinetUseState(cabinetId, useNum);
	}

	@Override
	public int updateCabinetUse(Long deviceId, String cabinetId, String useNum) {
		return deviceLocationMapper.updateCabinetUse(deviceId, cabinetId, useNum);
	}

    @Override
    public List<Map<String, Object>> getDeviceServerIpList(Long cabinetId) {
        return deviceLocationMapper.getDeviceServerIpList(cabinetId);
    }
}
